export class Cell {
    constructor(public cell_type : string, public metadata : {}, public source : string[]) {}
}
export class MarkdownCell extends Cell {
    constructor(text : string) {
        super('markdown', {}, []);
        this.source = text.split('\n').map(x => x + '\n');
        const len = this.source.length;
        if (len > 0) {
            this.source[len-1] = this.source[len-1].split('\n').join('');
        }
    }
}
export class CodeCell extends Cell {
    constructor(code : string) {
        super('code', {}, []);
        this.source = code.split('\n').map(x => x + '\n');
        const len = this.source.length;
        if (len > 0) {
            this.source[len-1] = this.source[len-1].split('\n').join('');
        }
    }
    public outputs: string[] = [];
    public execution_count: number = 0;
}
export class Notebook {
    constructor(public cells : Cell[] = []) {}
    public toObject() {
        // 小孩子不懂事，随便写的
        return {
            "metadata": {
                "kernelspec": {
                    "display_name": "Python 3 (ipykernel)",
                    "language": "python",
                    "name": "python3"
                },
                "language_info": {
                    "codemirror_mode": {
                        "name": "ipython",
                        "version": 3
                    },
                    "file_extension": ".py",
                    "mimetype": "text/x-python",
                    "name": "python",
                    "nbconvert_exporter": "python",
                    "pygments_lexer": "ipython3",
                    "version": "3.8.12"
                }
            },
            "nbformat": 4,
            "nbformat_minor": 5,
            "cells": this.cells
        }
    }
    public toBlob(){
        return new Blob([JSON.stringify(this.toObject())], {type: 'application/json'});
    }
}
